/**
 * @Author:  renyc
 * @Date: 2022年12月20日16:40:24
 */

import * as Cesium from "cesium/Cesium";
import Layer from "../Layer";
import LayerType from "../LayerType";

class PrimitiveLayer extends Layer{

    constructor(name, options){
        if(!options){
            throw new Error('PrimitiveLayer：options无效')
        }
        if(!options.source){
            throw new Error('PrimitiveLayer：source无效')
        }

        super(name, options);
        //this._delegate = new Cesium.PrimitiveCollection();
        this._type = LayerType.PRIMITIVE;
    }

    /**
     * 将Layer挂载到Viewer上
     * 由子类实现该函数
     * @private
     * @Override 
     * @param {Viewer} viewer 
     */
    _attach(){
        // if(this._viewer){
        //     this._viewer.scene.primitives.add(this._delegate);
        // }
        if(this._viewer&&this._source){
            this._viewer.scene.primitives.add(this._source._delegate);
        }
    }

    /**
     * 将Layer从Viewer上卸载
     * 由子类实现该函数
     * @private
     * @Override 
     */
    _detach(){
        // if(this._delegate){

        //     this._delegate.removeAll();
        //     this._viewer.scene.primitives.remove(this._delegate);
        // }

        if(this._source){
            this._source.cleanup();
            this._viewer.scene.primitives.remove(this._source._delegate);
        }
    }
}

export default PrimitiveLayer